/*
 * Copyright 2008 echo.khannedy@gmail.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ["Let's ROCK with JAVA"]
 * 
 * ["echo.khannedy@gmail.com"]
 * ["http://eecchhoo.wordpress.com/"]
 */
package open.usu.swing;

import java.awt.Color;
import javax.swing.JComponent;

/**
 * #{@link EProgress} merupakan komponen yang digunakan untuk menampilkan 
 * progress ato loading
 * @author usu
 * @since EGLassPane 1.1
 */
public class EProgress extends JComponent {

    private static final long serialVersionUID = -6466582191090203801L;
    /**
     * Property untuk indeterminate
     */
    public static final String PROPERTY_INDETERMINATE = "indeterminate";
    /**
     * Property untuk progressColor
     */
    public static final String PROPERTY_PROGRESS_COLOR = "progressColor";
    private boolean indeterminate;
    private Color progressColor;

    /**
     * Membuat EProgress baru
     */
    public EProgress() {
        super();
    }

    /**
     * Mengecek apakah EProgress berjalan indeterminate atau tidak
     * @return true jika indeterminate, dan false jika tidak
     */
    public boolean isIndeterminate() {
        return indeterminate;
    }

    /**
     * Mengubah nilai indeterminate EProgress
     * @param indeterminate nilai baru
     */
    public void setIndeterminate(boolean indeterminate) {
        // mendapatkan nilai indeterminate lama
        boolean oldValue = isIndeterminate();

        // mengubah nilai indeterminate
        this.indeterminate = indeterminate;

        // memberi tahu bahwa indeterminate berubah
        firePropertyChange(PROPERTY_INDETERMINATE, oldValue, indeterminate);
    }

    /**
     * Mendapatkan warna progress
     * @return Color
     */
    public Color getProgressColor() {
        return progressColor;
    }

    /**
     * Mengubah warna progress
     * @param progressColor warna baru
     */
    public void setProgressColor(Color progressColor) {
        // mendapatkan warna progress lama
        Color oldValue = getProgressColor();

        // mengubah warna progress
        this.progressColor = progressColor;

        // memberi tahu bahwa warna progress berubah
        firePropertyChange(PROPERTY_PROGRESS_COLOR, oldValue, progressColor);
    }
}
